﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRSystem.DBAccess;
using HRSystem.Entity;

namespace HRSystem
{
    public partial class FormSearch : Form
    {
        private BaseInfoAccess baseInfoAccess = new BaseInfoAccess();
        private List<BaseInfo> list = new List<BaseInfo>();

        public FormSearch()
        {
            InitializeComponent();
        }

        public void BindDate()
        {
            Person person = new Person();
            person.myBaseInfo.BaseChineseName = txtBaseChineseName.Text.Trim();
            person.myBaseInfo.BaseEnglishName = txtBaseEnglishName.Text.Trim();
            person.myBaseInfo.BaseGender = cboBaseGender.SelectedItem.ToString() == "全部" ? string.Empty : cboBaseGender.SelectedItem.ToString();
            person.myBaseInfo.BaseHighestEducation = txtBaseHighestEducation.Text.Trim();
            person.myBaseInfo.BaseGraduatedSchool = txtBaseGraduatedSchool.Text.Trim();
            person.myBaseInfo.BaseSpecialty = txtBaseSpecialty.Text.Trim();
            //person.myBaseInfo.BaseAge = txtBaseAge.Text.Trim();
            //person.myBaseInfo.BaseWorkExperienceYear = txtBaseGraduatedSchool.Text.Trim();//工作经验（年）
            person.myBaseInfo.BaseCurrentLocation = txtBaseCurrentLocation.Text.Trim();
            person.myBaseInfo.ExpandNativePlace = txtExpandNativePlace.Text.Trim();
            person.myBaseInfo.ExpandMarryBirthBaby = txtExpandMarryBirthBaby.Text.Trim();

            person.myResumeLabel.ResumeKeyword = txtResumeKeyword.Text.Trim();

            person.myResume.EducationSchoolName = txtEducationSchoolName.Text.Trim();
            person.myResume.EducationSchoolCharacter = txtEducationSchoolCharacter.Text.Trim();
            person.myResume.EducationSpecialty = txtEducationSpecialty.Text.Trim();
            person.myResume.EducationdDgree = txtEducationdDgree.Text.Trim();
            person.myResume.WorkCompany = txtWorkCompany.Text.Trim();
            person.myResume.WorkPosition = txtWorkPosition.Text.Trim();
            person.myResume.RelevanceCredentials = txtRelevanceCredentials.Text.Trim();

            person.myOperateProcessRecode.PhoneOperatePerson = txtPhoneOperatePerson.Text.Trim();
            person.myOperateProcessRecode.RecommenOperatePerson = txtRecommenOperatePerson.Text.Trim();
            person.myOperateProcessRecode.RecommenCompany = txtRecommenCompany.Text.Trim();
            person.myOperateProcessRecode.InterviewOperatePerson = txtInterviewOperatePerson.Text.Trim();
            person.myOperateProcessRecode.InterviewPerson = txtInterviewPerson.Text.Trim();
            person.myOperateProcessRecode.InterviewCompany = txtInterviewCompany.Text.Trim();

            person.myResultRecord.EmployCompany = txtEmployCompany.Text.Trim();
            person.myResultRecord.EmployDepartment = txtEmployDepartment.Text.Trim();
            person.myResultRecord.EmployPosition = txtEmployPosition.Text.Trim();

            list = baseInfoAccess.GetBaseInfo(person);

            if (list.Count <= 0)
            {
                PageCommon.ShowMessageByOK("没有数据。");
                dgvAll.DataSource = null;
                return;
            }

            dgvAll.Visible = true;
            dgvAll.RowHeadersVisible = false;
            dgvAll.DataSource = list;
            dgvAll.Columns.Clear();
            dgvAll.Columns.Add(PageCommon.BuildColumn("中文姓名", "BaseChineseName", "BaseChineseName", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("英文姓名", "BaseEnglishName", "BaseEnglishName", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("性别", "BaseGender", "BaseGender", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("最高学历", "BaseHighestEducation", "BaseHighestEducation", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("毕业学校", "BaseGraduatedSchool", "BaseGraduatedSchool", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("专业", "BaseSpecialty", "BaseSpecialty", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("出生年月", "BaseBirthday", "BaseBirthday", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("年龄", "BaseAge", "BaseAge", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("工作经验", "BaseWorkExperienceYear", "BaseWorkExperienceYear", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("现在所在地", "BaseAge", "BaseAge", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("国籍", "ExpandNationality", "ExpandNationality", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("籍贯", "ExpandNativePlace", "ExpandNativePlace", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("政治面貌", "ExpandPoliticsFace", "ExpandPoliticsFace", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("民族", "ExpandEthnic", "ExpandEthnic", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("婚育状况", "ExpandMarryBirthBaby", "ExpandMarryBirthBaby", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("健康情况", "ExpandHealth", "ExpandHealth", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("血型", "ExpandBloodType", "ExpandBloodType", true));
            dgvAll.Columns.Add(PageCommon.BuildColumn("爱好", "ExpandHobby", "ExpandHobby", true));

            dgvAll.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvAll.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dgvAll.Columns["detail"].Width = 42;
            dgvAll.ReadOnly = true;
            dgvAll.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private void dgvAll_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 18) && e.RowIndex != -1)
            {
                int id = Convert.ToInt32(dgvAll.CurrentRow.Cells["id"].Value);
                FormPersonDetail frm = new FormPersonDetail(id, this);
                frm.ShowDialog();
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            BindDate();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            if (pnlSearch.Height == 180)
            {
                btnShow.Text = "收起";
                pnlSearch.Height = 510;
             
            }
            else
            {
                btnShow.Text = "展开";
                pnlSearch.Height = 180;
                
            }
            InitSearchBar();

        }

        private void FormSearch_Load(object sender, EventArgs e)
        {
            InitSearchBar();
            cboBaseGender.Items.Add("全部");
            cboBaseGender.Items.Add("男");
            cboBaseGender.Items.Add("女");
            cboBaseGender.SelectedIndex = 0;
        }

     

        private void InitSearchBar()
        {
            
            int y = pnlSearch.Height - pnlSearchBar.Height;

            pnlSearchBar.Location = new Point(0, y);
        }

        private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar == 8))
            {
                e.Handled = false;
            }

            else
            {
                //MessageBox.Show("只能为数字！");
                e.Handled = true;
            }
        }
    }
}
